using UnityEngine;
using System.Collections;

public class MissonPanel : BasePanel {
	
	public UIGrid missonGrid;
	private GameObject missonItemPrb;
	public MissonManager manager{
		get{
			return (MissonManager)GameManager.GetInstatnce().GetManager(ManagerType.MISSION);
		}
	}
//	public 
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	public void Back(){
		GameManager.GetInstatnce().ShowPanel(PanelName.HeroPanel);
	}
	
	#region implemented abstract members of BasePanel
	public override IEnumerator Init ()
	{
		ResGameObject obj = new ResGameObject();
		yield return StartCoroutine(ResManager.GetInstance().Load("Prefabs/Items/MissonItem",obj));

		missonItemPrb = obj.obj as GameObject;
	}

	public override void Refresh ()
	{
		for(int i = 0;i < missonGrid.transform.childCount;i++){
			Transform obj = missonGrid.transform.GetChild(i);
			NGUITools.Destroy(obj.gameObject);
		}
		missonGrid.repositionNow = true;
		foreach(Misson misson in manager.GetMissonList()){
			if(misson != null){
				GameObject obj = NGUITools.AddChild(missonGrid.gameObject,missonItemPrb);
				obj.GetComponent<MissonItem>().SetItem(misson);
			}
		}
		missonGrid.repositionNow = true;
	}

	public override void Show ()
	{
		throw new System.NotImplementedException ();
	}

	public override void Hide ()
	{
		throw new System.NotImplementedException ();
	}
	#endregion
}
